package com.core.service;

import com.core.bean.Category;
import com.core.bean.Goods;
import com.core.bean.Product;
import com.core.dao.IGoodsDao;
import com.core.dao.IProductDao;
import com.core.dao.mybatismysql.MybatisMysqlFactory;
import java.util.List;

public class RemoveGoodsService {
    static IGoodsDao goodsDao = MybatisMysqlFactory.create(MybatisMysqlFactory.MYBATIS_MYSQL_DAO).getGoodsDao();
    public void remove(Goods goods)throws Exception{
        goodsDao.remove(goods.getId());
    }

    public void remove(Product product)throws Exception{
        List<Goods> byPropertyId = goodsDao.findByPropertyId(product.getId());
        for (Goods goods : byPropertyId) {
            goodsDao.remove(goods.getId());
        }
    }

    public void remove(Category category)throws Exception{
        IProductDao productDao = MybatisMysqlFactory.create(MybatisMysqlFactory.MYBATIS_MYSQL_DAO).getProductDao();
        List<Product> byCid = productDao.findByCid(category.getId());
        for (Product product : byCid) {
            List<Goods> byPropertyId = goodsDao.findByPropertyId(product.getId());
            for (Goods goods : byPropertyId) {
                goodsDao.remove(goods.getId());
            }
        }
    }

}
